{block name="style"}
{/block}
{block name="content"}
<div class="info-header">
    <div class="layui-row">
        <div class="layui-col-xs3">
            <label class="layui-form-label">业务单号</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.ref_sn}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">应付款日期</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.biz_date}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">付款日期</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.real_date}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">审批状态</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.check_status}" readonly class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs3">
            <label class="layui-form-label">开户行</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.bank}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">开户名</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.bank_user}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">银行账号</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.account}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">开户地址</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.bank_address}" readonly class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs3">
            <label class="layui-form-label">付款状态</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.pay_status}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">付款方式</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.pay_type?:''}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">币种</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.currency}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">应付金额</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.act_money|abs}" readonly class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs3">
            <label class="layui-form-label">应付手续费</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.service_charge|abs}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">已付金额</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.real_money|abs}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">付款人</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.payUser ? $payment.payUser.nickname : ''}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">税</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.tax|abs}" readonly class="layui-input">
            </div>
        </div>
    </div>
    {if $payment.is_invoice && $payment.invoice}
    <div class="layui-row">
        <div class="layui-col-xs3">
            <label class="layui-form-label">发票类型</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.invoice.type}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">发票抬头</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.invoice.title}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">发票税号</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.invoice.tax_code}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">发票金额</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.invoice_money|abs}" readonly class="layui-input">
            </div>
        </div>
    </div>
    {/if}
    <div class="layui-row">
        <div class="layui-col-xs3">
            <label class="layui-form-label">费用说明</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.cost_desc}" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" value="{$payment.remark}" readonly class="layui-input">
            </div>
        </div>
    </div>
</div>
<div class="info-body">
    {if $payment->getData('check_status') != \app\common\model\JobFlowModule::CHECK_NO_NEED}
    <div class="layui-row job-flow-margin">
        {include file="public/jobFlow" /}
    </div>
    {/if}
    <div class="layui-row">
        <div class="layui-col-xs4">
            <h2>付款单详情</h2>
        </div>
        <div class="layui-col-xs8">
            <div class="layui-btn-group" style="float: right;">
                {if $is_show_payment}
                <a href="{:url('/fac/payment/save', ['payment_id' => $payment->payment_id])}" width-form="550px" height-form="50%" class="ajax-form layui-btn">添加付款</a>
                {/if}
                {if $is_show_check}
                    <a item="{$payment.payment_id}" class="layui-btn check-job-flow-reload">审批</a>
                {/if}
                <button type="button" id="print-payment" class="layui-btn">打印付款单</button>
                <button type="button" item="{$attachment_type_invoice}" class="file-upload layui-btn">上传发票</button>
                <button type="button" item="{$attachment_type_contract}" class="file-upload layui-btn">上传合同</button>
                <button type="button" item="{$attachment_type_other}" class="file-upload layui-btn">上传附件</button>
            </div>
        </div>
    </div>
    {if !empty($pay_info)}
        {$pay_info|raw}
    {/if}
</div>
{/block}
{block name="script"}
<script type="text/javascript">
layui.use(['layer', 'jquery', 'upload'], function()
{
    var layer = layui.layer
        , upload = layui.upload
        , $ = layui.jquery;

    $("body").on("change", "#save-service-charge", function()
    {
        var actMoney = $("#save-act-money").val() * 1
            , curMoney = $(this).val() * 1;
        if(isNaN(curMoney) || curMoney >= actMoney) return;
        $("#save-real-money").val(actMoney + curMoney);
    });

    // 打印付款单
    $("#print-payment").click(function()
    {
        // @todo
    });

    // 上传发票合同，附件
    $(".file-upload").each(function()
    {
        var $this = $(this);
        upload.render({
            elem: this
            , url: '{:url("file/upload",["type"=>"document"])}'
            , accept: 'file' //普通文件
            , field: "file"
            , multiple: true
            , before: function (obj) {
                layer.load(0, {shade: false});
            }
            , done: function (response, index, upload) {
                layer.closeAll('loading');
                if (response.code != 1) {
                    layer.closeAll('loading');
                    var icon = response.code == 1 ? 6 : 5;
                    layer.msg(response.msg, {icon: icon, time: 1500});
                    return;
                }
                var type = $this.attr("item");
                var payId = {$payment.payment_id};
                $.post("{:url('upload')}", {"path": response.data.src, "name": response.data.name, "type": type, "payment_id": payId}).done(function (response)
                {
                    var icon = response.code == 1 ? 6 : 5;
                    layer.msg(response.msg, {icon: icon, time: 1500});
                });
            }
            , error: function (index, upload) {
                layer.msg('上传失败');
            }
        });
    });
});
</script>
{/block}